<?php

/**
 * This is the model class for table "tbl_dispatchboard_assignments".
 *
 * The followings are the available columns in table 'tbl_dispatchboard_assignments':
 * @property integer $id
 * @property string $side
 * @property string $empno
 * @property string $dispatchboardid
 */
class DispatchboardAssignments extends CActiveRecord
{

	const RIGHT_SIDE='R';
	const LEFT_SIDE='L';

	/**
	 * Returns the static model of the specified AR class.
	 * @return DispatchboardAssignments the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_dispatchboard_assignments';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('empno, dispatchboardid', 'required'),
			array('side, dispatchboardid', 'length', 'max'=>45),
			array('empno', 'length', 'max'=>4),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, side, empno, dispatchboardid', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'employee'=>array(self::BELONGS_TO,'Employees','empno'),
			'dispatchboard'=>array(self::BELONGS_TO,'DispatchBoard','dispatchboardid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
		      	'id' => 'Id',
			'side' => 'Side',
			'empno' => 'Empno',
			'dispatchboardid' => 'Dispatchboardid',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('side',$this->side,true);
		$criteria->compare('empno',$this->empno,true);
		$criteria->compare('dispatchboardid',$this->dispatchboardid,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function getSideOptions()
	{
		return array(  
			self::RIGHT_SIDE=>'Right',
			self::LEFT_SIDE=>'Left',
		);
	}

}
